import java.util.ArrayList;
import java.util.List;

public class TestMap {
    public static void main(String[] args) {
        String filename = "Map/pride-and-prejudice.txt";
        Map<String, Integer> bstMap = new BSTMap<>();
        Map<String, Integer> linkedListMap = new LinkedListMap<>();
        double bstMapTime = test(bstMap, filename);
        double linkedListMapTime = test(linkedListMap, filename);
        System.out.println("bstMapTime = " + bstMapTime);
        System.out.println("linkedListMapTime = " + linkedListMapTime);
    }

    private static double test(Map<String, Integer> map, String filename) {
        long startTime = System.nanoTime();
        System.out.println(filename);
        List<String> words = new ArrayList<>();
        if (FileOperation.readFile("Map/pride-and-prejudice.txt", words)) {
            System.out.println("Total words:" + words.size());
            for (String word : words) {
                if (map.contains(word)) map.set(word, map.get(word) + 1);
                else map.add(word, 1);
            }
            System.out.println("Total different word:" + map.getSize());
            System.out.println("Frequency of PRIDE：" + map.get("pride"));
            System.out.println("Frequency of PREJUDICE：" + map.get("prejudice"));
        }
        System.out.println();
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }
}
